import { callCloud } from './cloud';
const billManager = uniCloud.importObject('billManager')
const getUserId = ()=>{
	const userInfo = uni.getStorageSync('userInfo')
	return userInfo._id
}

export async function getProperties() {
    const result = await callCloud('getProperties', {
		owner: getUserId()
    })
    return result?.data
}

export async function getLabels(userName, password) {
	const owner = uni.getStorageSync('userInfo')?._id
	if (!owner) {
		return false
	}
    const result = await callCloud('getLabels', {
		owner
    })
    return result?.data
}

export async function getBills(options){
	let params = {
		owner: getUserId(),
	}
	options?.dateRange && (params.dateRange = options.dateRange);
	const res = await billManager.getBill(params)
	return res.data
}

export async function addBill(options){
	options.owner = getUserId()
	const res = await billManager.addBill(options)
	return res
}